package com.ganeshkrishnan.globald.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.ganeshkrishnan.globald.abstracts.BaseObject;

@SuppressWarnings("serial")
@Entity
public class Deployment extends BaseObject {
	private Long			ID;

	//Number of resources deployed
	private long			AvailResources;
	//kind of resource
	private int				ResourceType;
	//Owner of deployment
	private PersonLocation	personLocation;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getID() {
		return ID;
	}

	public void setID(Long iD) {
		ID = iD;
	}

	@ManyToOne
	@JoinColumn(name = "LocationID", referencedColumnName = "ID", updatable = true, insertable = true)
	public PersonLocation getPersonLocation() {
		return personLocation;
	}

	public void setPersonLocation(PersonLocation personLocation) {
		this.personLocation = personLocation;
	}

	public long getAvailResources() {
		return AvailResources;
	}

	public void setAvailResources(long availResources) {
		AvailResources = availResources;
	}

	public int getResourceType() {
		return ResourceType;
	}

	public void setResourceType(int resourceType) {
		ResourceType = resourceType;
	}

	@Override
	public boolean equals(Object obj) {
		if (null == obj)
			return false;
		if (this == obj)
			return true;
		if (!(obj instanceof Deployment))
			return false;
		Deployment thispl = (Deployment) obj;
		//return //(personLocation != null ? (personLocation.equals(thispl.getPersonLocation())) : true)
		return (thispl.getResourceType() == ResourceType && thispl.personLocation == personLocation);
	}

	@Override
	public int hashCode() {
		return /* (personLocation != null ? personLocation.hashCode() : 0) + */(ResourceType * 32)
				+ ((personLocation != null ? personLocation.hashCode() : 0) * 32);
	}

	@Override
	public String toString() {
		return "Deployment [ Location:" + (personLocation) + " /Res:" + (ResourceType) + "/ Avail" + AvailResources
				+ "]";
	}
}
